package org.lifxue.jqda.ui;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.LayoutStyle;
import javax.swing.WindowConstants;

/**
 * 
 * @Description:
 * @Author: zhangzuoqiang
 * @Date: Sep 26, 2011
 */
public class AboutJDialog extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static AboutJDialog about;

	/**
	 * Creates new form AboutJDialog
	 * 
	 * @param parent
	 * @param modal
	 */
	public AboutJDialog(Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public AboutJDialog(boolean modal) {
		super(new JFrame(), modal);
		initComponents();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = getSize();
		setLocation(new Point((screenSize.width - frameSize.width) / 2,
				(screenSize.height - frameSize.width) / 2));

	}

	public static AboutJDialog getInstance(boolean modal) {
		synchronized (AboutJDialog.class) {
			if (about == null) {
				about = new AboutJDialog(modal);
			}
		}
		return about;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">
	private void initComponents() {
		jLabel1 = new JLabel();
		jLabel2 = new JLabel();
		jLabel3 = new JLabel();
		jLabel4 = new JLabel();
		closejButton = new JButton();
		jLabel5 = new JLabel();
		jLabel6 = new JLabel();

		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("关于");
		setIconImage(Toolkit.getDefaultToolkit().createImage(
				getClass().getResource("/org/lifxue/jqda/ui/butterfly16.png")));

		jLabel1.setIcon(new ImageIcon(getClass().getResource(
				"/org/lifxue/jqda/ui/about.png")));

		jLabel2.setText("桌面快捷应用软件java版-JQDA");

		jLabel3.setText("版本：");

		jLabel4.setText("2.0");

		closejButton.setText("关闭");
		closejButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				closejButtonActionPerformed(evt);
			}
		});

		jLabel5.setText("作者：");

		jLabel6.setText("lifxue");

		GroupLayout layout = new GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(jLabel1)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.TRAILING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(18, 18,
																		18)
																.addGroup(
																		layout.createParallelGroup(
																				GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabel2)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										jLabel3)
																								.addGap(18,
																										18,
																										18)
																								.addComponent(
																										jLabel4))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										jLabel5)
																								.addGap(18,
																										18,
																										18)
																								.addComponent(
																										jLabel6)))
																.addContainerGap(
																		74,
																		Short.MAX_VALUE))
												.addGroup(
														layout.createSequentialGroup()
																.addPreferredGap(
																		LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		closejButton)
																.addContainerGap()))));
		layout.setVerticalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addComponent(jLabel1)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(jLabel2)
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel3)
												.addComponent(jLabel4))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel5)
												.addComponent(jLabel6))
								.addPreferredGap(
										LayoutStyle.ComponentPlacement.RELATED,
										55, Short.MAX_VALUE)
								.addComponent(closejButton).addContainerGap()));
		pack();
	}

	private void closejButtonActionPerformed(ActionEvent evt) {
		this.setVisible(false);
		dispose();
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				AboutJDialog dialog = new AboutJDialog(new JFrame(), true);
				dialog.addWindowListener(new WindowAdapter() {

					@Override
					public void windowClosing(WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);
			}
		});
	}

	private JButton closejButton;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JLabel jLabel6;
}
